package com.zdy.reflection;

/**
 * Created by 逸足天涯
 * on 3/5/2020.
 */

//测试类的创建的方法有那些
public class Test03 {
    public static void main(String[] args) throws ClassNotFoundException{
        Person person = new Student();
        System.out.println("这个人是：" + person.name);

        //方式一 通过已经实例化的对象获得
        Class c1 = person.getClass();
        System.out.println(c1.hashCode());

        //方式二 Class.forName获得
        Class c2 = Class.forName("com.zdy.reflection.Student");
        System.out.println(c2.hashCode());

        //方法三、通过类名.class获得
        Class c3 = Student.class;
        System.out.println(c3.hashCode());

        //方式四 通过内置类型的包装类的都有一个Type属性。
        Class c4 = Integer.TYPE;
        System.out.println(c4.hashCode());

        //获取父类
        Class superclass = c1.getSuperclass();
        System.out.println(superclass);

    }
}
class Person{
    public  String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}
class Student extends Person{
    public Student() {
        this.name = "学生";
    }
}
class Teacher extends Person{
    public Teacher() {
        this.name = "老师";
    }
}
